package com.example.glidelearningproject.fragment.option;

import static com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions.withCrossFade;
import static com.example.glidelearningproject.fragment.option.RequestOptionsUseFragment.OPTION_KEY;

import android.graphics.Bitmap;
import android.os.Bundle;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestBuilder;
import com.bumptech.glide.load.resource.bitmap.BitmapTransitionOptions;
import com.bumptech.glide.request.RequestOptions;
import com.example.glidelearningproject.GlideApp;
import com.example.glidelearningproject.R;
import com.xuexiang.xpage.annotation.Page;
import com.xuexiang.xpage.base.XPageFragment;

import butterknife.BindView;

@Page(name = "GlideOptions应用")
public class GlideOptionsFragment extends XPageFragment {
    private int optionType;
    @BindView(R.id.imageView)
    ImageView imageView;
    @Override
    protected int getLayoutId() {
        return R.layout.fragment_dialog_picture;
    }

    @Override
    protected void initArgs() {
        super.initArgs();
        Bundle args = getArguments();
        optionType = args.getInt(OPTION_KEY);
    }

    @Override
    protected void initViews() {
        if (optionType == 0) {
            GlideApp.with(this)
                    .load("https://upload-images.jianshu.io/upload_images/1343879-7851a6259a7d7474.jpeg?imageMogr2/auto-orient/strip|imageView2/2/w/1200/format/webp")
                    .centerCrop()
                    .into(imageView);
        }else if(optionType == 1){
            RequestOptions requestOptions = new RequestOptions().fitCenter();
            GlideApp.with(this)
                    .load("https://upload-images.jianshu.io/upload_images/25503572-cd13e74c0aa0ebea.jpg?imageMogr2/auto-orient/strip|imageView2/2/w/800/format/webp")
                    .apply(requestOptions)
                    .into(imageView);
        }else if (optionType == 2){
            BitmapTransitionOptions options = BitmapTransitionOptions.withCrossFade(4000);
            GlideApp.with(this)
                    .asBitmap()
                    .load("https://upload-images.jianshu.io/upload_images/14255230-e4a14c9fa5d4224d.jpg?imageMogr2/auto-orient/strip|imageView2/2/w/383/format/webp")
                    /*.transition(withCrossFade())*/
                    .transition(options)
                    .into(imageView);
        }else if(optionType == 3){
            GlideApp.with(this)
                    .load("https://upload-images.jianshu.io/upload_images/24388310-1d5571ecac387f39.jpeg?imageMogr2/auto-orient/strip|imageView2/2/w/679/format/webp")
                    .thumbnail(GlideApp.with(this)
                    .load("https://upload-images.jianshu.io/upload_images/24388310-1d5571ecac387f39.jpeg?imageMogr2/auto-orient/strip|imageView2/1/w/300/h/240"))
                    .into(imageView);
        }else if(optionType == 4){
            RequestBuilder<Bitmap> bitmapRequestBuilder = GlideApp.with(this).asBitmap();
            bitmapRequestBuilder.load("https://upload-images.jianshu.io/upload_images/4155146-f92fb8ffbd41b8bd.jpg?imageMogr2/auto-orient/strip|imageView2/2/w/658/format/webp").into(imageView);
        }else if(optionType == 5){
            GlideApp.with(this)
                    .load("https://upload-images.jianshu.io/upload_images/4155146-fd765000f7baeef81.jpg?imageMogr2/auto-orient/strip|imageView2/2/w/618/format/webp")
                    .error(GlideApp.with(this).load("https://upload-images.jianshu.io/upload_images/4155146-ebf78443e07e74a1.jpg?imageMogr2/auto-orient/strip|imageView2/2/w/960/format/webp"))
                    .into(imageView);
        }else if(optionType == 6){
            Glide.with(this)
                    .load("https://upload-images.jianshu.io/upload_images/4155146-b413e200d8fd0abe.jpg?imageMogr2/auto-orient/strip|imageView2/2/w/1200/format/webp")

                    .into(imageView);
        }
    }

    @Override
    protected void initListeners() {

    }
}
